/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.chlitina.store.modules.sms.service;

import java.util.List;
import java.util.Map;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.chlitina.store.common.persistence.Page;
import com.chlitina.store.common.service.BaseService;
import com.chlitina.store.modules.sms.dao.StoreDiagnoseFomulaDao;
import com.chlitina.store.modules.sms.entity.StoreDiagnoseFomula;
import com.google.common.collect.Maps;

/**
 * 店面诊断计算规则Service
 * @author liujiang
 * @version 2013-08-01
 */
@Component
@Transactional(readOnly = true)
public class StoreDiagnoseFomulaService extends BaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(StoreDiagnoseFomulaService.class);
	
	@Autowired
	private StoreDiagnoseFomulaDao storeDiagnoseFomulaDao;
	
	public StoreDiagnoseFomula get(Long id) {
		return storeDiagnoseFomulaDao.findOne(id);
	}
	
	public Page<StoreDiagnoseFomula> find(Page<StoreDiagnoseFomula> page, StoreDiagnoseFomula storeDiagnoseFomula) {
		page.setPageSize(10);
		DetachedCriteria dc = storeDiagnoseFomulaDao.createDetachedCriteria();
		dc.addOrder(Order.asc("id"));
		return storeDiagnoseFomulaDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(StoreDiagnoseFomula storeDiagnoseFomula) {
		storeDiagnoseFomulaDao.save(storeDiagnoseFomula);
	}
	
	@Transactional(readOnly = false)
	public void delete(Long id) {
		storeDiagnoseFomulaDao.delete(id);
	}
	
	public Map<Long, String> getFomulaMap() {
		Map<Long, String> map = Maps.newLinkedHashMap();
		List<StoreDiagnoseFomula> list = (List<StoreDiagnoseFomula>) storeDiagnoseFomulaDao.findAll();
		for (StoreDiagnoseFomula a : list) {
			map.put(a.getId(), a.getName());
		}
		return map;
	}
}
